#pragma once

#include <chrono>
#include <iostream>
#include <string>

class TicToc
{
public:
    TicToc()
    {
        tic();
    }

    void tic()
    {
        start = std::chrono::system_clock::now();
    }

    double toc(const std::string &msg)
    {
        end = std::chrono::system_clock::now();
        std::chrono::duration<double> elapsed_seconds = end - start;
        double elapsed_ms = elapsed_seconds.count() * 1000;
        if (!msg.empty())
        {
            // Optional: You can uncomment the line below to see performance logs
            // std::cout << msg << ": " << elapsed_ms << " ms" << std::endl;
        }
        return elapsed_ms;
    }

private:
    std::chrono::time_point<std::chrono::system_clock> start, end;
};